home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Stacks / Updates⁄New / TEXAS for BMUG / C progs / TEXAS XFCNs ƒ / closeFileXFCN.1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-29  |  1.5 KB  |  91 lines  |  [TEXT/KAHL]

  1. /* a HyperCard XFCN that closes the chosen text
  2.  * file, given its file refNum as an input argument ... returns
  3.  * 1 if successful, null string if failure....
  4.  *
  5.  * make it XFCN number 296 and call it "closeFile"
  6.  *
  7.  * 871127 ^z
  8.  */
  9.  
  10. #include <MacTypes.h>
  11. #include <OSUtil.h>
  12. #include <FileMgr.h>
  13. #include <HyperXCmd.h>
  14. #include <proto.h>
  15.  
  16. pascal void main (XCmdBlockPtr paramPtr);
  17. void complain (XCmdBlockPtr paramPtr);
  18.  
  19. pascal void main (paramPtr)
  20.   XCmdBlockPtr paramPtr;
  21.   {
  22.     Handle answer;
  23.     int refNum0;
  24.  
  25.     if (paramPtr->paramCount != 1)
  26.       {
  27.           complain (paramPtr);
  28.           return;
  29.       }
  30.           
  31.     refNum0 = atol (*(paramPtr->params[0]));
  32.  
  33.     if (FSClose (refNum0) != noErr)
  34.       {
  35.           complain (paramPtr);
  36.           return;
  37.       }
  38.     
  39.     answer = NewHandle (2);
  40.     **answer = '1';
  41.     *(*answer + 1) = '\0';    
  42.     paramPtr->returnValue = answer;
  43.     return;
  44.   }
  45.  
  46.  
  47.  
  48. /* function to beep and set the return string to null (= "")
  49.  */
  50.  
  51. void complain (paramPtr)
  52.   XCmdBlockPtr paramPtr;
  53.   {
  54.     Handle answer;
  55.     
  56.       SysBeep (10);
  57.       answer = NewHandle (1);
  58.       **answer = '\0';
  59.     paramPtr->returnValue = answer;
  60.     return;
  61.   }
  62.  
  63.  
  64.  
  65. /* function to convert alphabetic string to a long integer ... from LSC
  66.  * library.... simplified to avoid using isspace() & isdigit() .... */
  67.  
  68. long atol (s)
  69.   register char *s;
  70.   {
  71.     register char signflag = 0;
  72.     register long r = 0;
  73.  
  74.     while ((*s == ' '))
  75.         s++;
  76.         
  77.     if (*s == '-')
  78.       {
  79.         signflag = 1;
  80.         s++;
  81.       }
  82.     else if (*s == '+')
  83.          s++;
  84.  
  85.     while (*s >= '0' && *s <= '9') 
  86.         r = r * 10 + (*s++ - '0');
  87.     
  88.     return (signflag ? -r : r);
  89. }
  90.  
  91.